<template>
  <!-- 公司内容 -->
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <!-- 左侧占据20份 -->
    <el-col :span="20">
      <span>{{ item.name }}</span>
    </el-col>
    <!-- 右侧占据4份 -->
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <!-- 左侧负责人占据12份 -->
        <el-col :span="12">{{ item.manager || '负责人' }}</el-col>
        <!-- 右侧是操作占据12份 -->
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu v-if="item.manager" slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
            <el-dropdown-menu v-else slot="dropdown">
              <el-dropdown-item command="add">添加部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 处理下拉菜单的点击事件
    handleCommand(com) {
      //   console.log(com)
      // 判断command值，选择性的执行代码
      //   选用switch-case语句
      switch (com) {
        case 'add':
          // 通知父组件,并携带部门对象给父组件
          this.$emit('add-dept', this.item)
          break
        case 'edit':
          // console.log('编辑部门')
          this.$emit('edit-dept', this.item)
          break
        case 'del':
          // console.log('删除部门')
          //   通知父组件,并携带id给父组件
          this.$emit('del-dept', this.item.id)
          break
      }
    }
  }
}
</script>

<style>
</style>
